<script>
  import {
    addToShortcutScope,
    removeFromShortcutScope
} from '../../_utils/shortcuts.js'
  export default {
    data: () => ({ scope: 'global', key: null }),
    oncreate () {
      const { scope, key } = this.get()
      addToShortcutScope(scope, key, this)
    },
    ondestroy () {
      const { scope, key } = this.get()
      removeFromShortcutScope(scope, key, this)
    },
    methods: {
      onKeyDown (event) {
        event.stopPropagation()
        event.preventDefault()
        this.fire('pressed', {
          key: event.key,
          timeStamp: event.timeStamp
        })
      }
    }
  }
</script>
